var url_data_RewardActivityList = webroot + '/admin/rewardActivity/getRewardActivityList';//回馈活动列表url
var url_page_RewardActivityList = webroot + '/admin/rewardActivity/toRewardActivityListPage';//回馈活动列表页面url
var url_add_RewardActivity = webroot + '/admin/rewardActivity/insertRewardActivity';//新增活动url
var url_edit_RewardActivity = webroot + '/admin/rewardActivity/updateRewardActivity';//修改活动url
/**
 * 保存活动
 */
function saveRewardActivity(){
	var bootstrapValidator =  $('#addForm').data('bootstrapValidator');
    bootstrapValidator.validate();
    if(!bootstrapValidator.isValid()){
        return;
    }
    var pic = $("#activityPic").val();
    if(pic == null || pic == undefined || pic == ""){
    	$.alert("请上传活动图片");
    	return;
    }
    $.confirm({
        type: 'blue',
        animationSpeed: 300,
        title:"确定提交吗?",
        content: $('#createDialog').html(),
        buttons: {
            confirm: {
                text: '确认',
                btnClass: 'waves-effect waves-button',
                action: function () {
                     // 编辑确定，执行数据操作
                    $.ajax({
                        url : url_add_RewardActivity,
                        data : $("#addForm").serialize(),
                        dataType : "json",
                        type:'POST',
                        success:function (data) {
                            if (data.result=='000') {
                                $.alert(data.msg);
                                window.location.href = url_page_RewardActivityList;
                            } else if(data.result=='111') {
                                $.alert(data.msg);
                            } else {
                                $.alert('系统异常，错误代码:'+data.result);
                            }
                        },error:function () {
                            $.alert("系统繁忙稍后再试");
                        }
                        
                    });
                }
            },
            cancel: {
                text: '取消',
                btnClass: 'waves-effect waves-button'
            }
        }
    });
}
/**
 * 修改活动
 */
function updateRewardActivity(){
	var bootstrapValidator =  $('#addForm').data('bootstrapValidator');
	bootstrapValidator.validate();
	if(!bootstrapValidator.isValid()){
		return;
	}
	var pic = $("#activityPic").val();
	if(pic == null || pic == undefined || pic == ""){
		$.alert("请上传活动图片");
		return;
	}
	$.confirm({
		type: 'blue',
		animationSpeed: 300,
		title:"确定提交吗?",
		content: $('#createDialog').html(),
		buttons: {
			confirm: {
				text: '确认',
				btnClass: 'waves-effect waves-button',
				action: function () {
					// 编辑确定，执行数据操作
					$.ajax({
						url : url_edit_RewardActivity,
						data : $("#addForm").serialize(),
						dataType : "json",
						type:'POST',
						success:function (data) {
							if (data.result=='000') {
								$.confirm({
				    				type: 'blue',
				    				animationSpeed: 300,
				    				title: "提示",
				    				content: "修改成功返回上一页？",
				    				buttons: {
				    					confirm: {
				    						text: '是',
				    						btnClass: 'waves-effect waves-button',
				    						action: function () {
				    							window.location.href = url_page_RewardActivityList;
				    						}
				    					}, cancel: {text: '否', btnClass: 'waves-effect waves-button',action:function () {
				    							return;
				    						}
				    					}
				    				}
								});
							} else if(data.result=='111') {
								$.alert(data.msg);
							} else {
								$.alert('系统异常，错误代码:'+data.result);
							}
						},error:function () {
							$.alert("系统繁忙稍后再试");
						}
						
					});
				}
			},
			cancel: {
				text: '取消',
				btnClass: 'waves-effect waves-button'
			}
		}
	});
}
